package com.dingshi.security.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

import com.dingshi.security.R;

public class SignalView extends LinearLayout {

	private LayoutInflater mInflater;
	private LinearLayout mBarView, signal1, signal2, signal3, signal4, signal5;

	public SignalView(Context context) {
		super(context);
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mBarView = (LinearLayout) mInflater
				.inflate(R.layout.signallayout, null);
		addView(mBarView);
		signal1 = (LinearLayout) mBarView.findViewById(R.id.signal1);
		signal2 = (LinearLayout) mBarView.findViewById(R.id.signal2);
		signal3 = (LinearLayout) mBarView.findViewById(R.id.signal3);
		signal4 = (LinearLayout) mBarView.findViewById(R.id.signal4);
		signal5 = (LinearLayout) mBarView.findViewById(R.id.signal5);

	}

	public SignalView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mBarView = (LinearLayout) mInflater
				.inflate(R.layout.signallayout, null);
		addView(mBarView);
		signal1 = (LinearLayout) mBarView.findViewById(R.id.signal1);
		signal2 = (LinearLayout) mBarView.findViewById(R.id.signal2);
		signal3 = (LinearLayout) mBarView.findViewById(R.id.signal3);
		signal4 = (LinearLayout) mBarView.findViewById(R.id.signal4);
		signal5 = (LinearLayout) mBarView.findViewById(R.id.signal5);
	}

	public void setSignalValue(int value) {
//		Log.e("SignalView", "value is " + value);
		
		if(value<99) {
			if(value>=0) {
				setColorFromSignal(signal1);
			}
			if(value>=6) {
				setColorFromSignal(signal2);
			}
			if(value>=12) {
				setColorFromSignal(signal3);
			}

			if(value>=18) {
				setColorFromSignal(signal4);
			}

			if(value>=24) {
				setColorFromSignal(signal5);
			}
			
		}else {
			//没有卡
		}
		
	}

	public void setColorFromSignal(LinearLayout ll) {
		ll.setBackgroundColor(Color.parseColor("#ffffff"));
	}
	public void setColorFromSignal(LinearLayout ll, int value, int leavel) {
//		Log.e("SignalView", "value is " + value + " leavel is " + leavel);
		if (value > leavel) {
			ll.setBackgroundColor(Color.parseColor("#ffffff"));
		} else {
			ll.setBackgroundColor(Color.parseColor("#989898"));
		}
	}
}
